#ifndef TRADESERVER_H
#define TRADESERVER_H
#include "shorttcpclient.h"
#include "Msg/HashtableMsg.h"
#include "View/comboData.h"
#include <QStringListModel>
#include "View/rspinterface.h"

struct BranchInfo
{
    QString branch_id;
    QString branch_name;
    QString branch_level;
    QString p_branch_id;
};

struct CustGrade
{
    QString grade_id;
    QString branch_id;
    QString grade_name;
};
class TradeServer
{
public:
    TradeServer();

    void InitServerAddr(HashtableMsg htm_server_list);

    bool Login(const QString qsUser, const QString qsPwd, QString& qsErrMsg);

    //9010 从服务器获取最新的代理机构信息
    bool RequestBranchInfo();

    ComboData* GetMyBranchs();

    //9025 获取最新客户级别信息
    void GetGradeInfo();

    //1002 获得合约代码列表
    void GetProdCode();

    //获取合约代码
    QStringList GetSomeProdCode(const QStringList qsMarketList);

    ComboData* GetCustGradeByBranchs(const QString qsBranchId,bool bAll=true);

    //3069
    bool QueryForceOrder(QString& tipInfo,RspInterface *pRsp,const QString reqInfo);

    //3095
    bool QueryRiskCustCount(QString& tipInfo,RspInterface *pRsp,const QString reqInfo);

    //3096
    bool QueryAgentRiskCustCount(QString& tipInfo,RspInterface *pRsp,const QString reqInfo);

    //3094
    bool QueryHisRiskCustList(QString& tipInfo,RspInterface *pRsp,const QString reqInfo);

    QString GetCustGradeName(const QString qsID);

    QString GetBranchName(const QString qsID);
    QString GetBranchID(const QString qsName);
protected:
    bool GetNetAddress(QString& qsIP, int& nPort);
    //请求被正常处理了返回true，参数错误或者通讯失败都返回false
    bool TransForNormal(const std::string& sReq, std::string& sRsp, QString& qsErrMsg);
private:
    ShortTcpClient  m_comClient;
    HashtableMsg    m_server_list;
    unsigned int    m_nCurSevPos;
    QMap<QString,BranchInfo>    m_mapBranch;
    QList<CustGrade>    m_lAllCustGrade;
    QMap<QString,QList<CustGrade>>  m_mapBranchCustGrade;   //<branch,
    HashtableMsg    m_htm_prod_code;
};

#endif // TRADESERVER_H
